function y=rebalance_test(Quantitative,MedianPrice,Symbol,lastQuantitative,lastMedianPrice,lastSymbol,v)
Num=length(Symbol);
value0=lastQuantitative'*lastMedianPrice;
A=Quantitative'*MedianPrice;
[b1,ib1]= setdiff(lastSymbol,Symbol);
B1=v*abs(lastQuantitative(ib1))'*lastMedianPrice(ib1);
[b2,ib2]= setdiff(Symbol,lastSymbol);
B2=v*abs(Quantitative(ib2))'*MedianPrice(ib2);
[b3, ia3, ib3]=intersect(lastSymbol,Symbol);
B3=v*abs(lastQuantitative(ia3)-Quantitative(ib3))'*MedianPrice(ib3);
B=B1+B2+B3;
rebalance_diff=A+B-value0;
value=Quantitative'*MedianPrice;
NonlCon=(Quantitative.*MedianPrice)/value-1/Num;
NonlCon(1)=rebalance_diff;
y=sum(NonlCon.^2);